<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=640px,user-scalable=no,target-densitydpi=device-dpi" />
		<link rel="stylesheet" href="../css/css.css" type="text/css" />
		<script type="text/javascript" src='../js/jquery.min.js'></script>
		<script type="text/javascript" src='../js/main_in.js'></script>
		<script type="text/javascript" src='../js/common.js'></script>
		<script type="text/javascript" src='../js/jquery.qrcode.min.js'></script>
		<title></title>
		<script type="text/javascript">
			var uid = window.localStorage["uid"];
			var name = window.localStorage["name"];
			var lgname = window.localStorage["lgname"];
			var imgaes_url = '';
			
			$(function(){
				$("#lgname").val(lgname);
				$("#name").val(name);
			})
			
function doadd(){
					var cartype = $("#cartype").val();
                    var name = $("#name").val();
                    var carid = $("#carid").val();
                    var money = $("#money").val();
                    var remark = $("#remark").val();
                    var url = '';
                    if (imgaes_url == '' || imgaes_url == null) {
                        alert("请上传充值凭证");
                        return false;
                    }
                    $.ajax({
                        url: "http://insure.unair.cn/sqls_h.php",
                        type: "POST",
                        data: {
                            "cartype": cartype,
                            "name": name,
                            "carid": carid,
                            "money": money,
                            "remark": remark,
                            "url": imgaes_url,
                            "uid" : uid,
                            "lgname":lgname
                            
                        },
                        success: function(data) {
                            if (data == 'sucess') {
                                plus.nativeUI.alert('申请成功',function(){
									clicked('./myinfo.html');
								},'油卡充值');
                            } else {
                                plus.nativeUI.alert('申请失败',function(){
									
								},'油卡充值');
                            }
                        },
                        error: function(data) {
                            plus.nativeUI.alert('申请失败',function(){
									
								},'油卡充值');
                        }
                    });
}


// 上传文件
var server="http://insure.unair.cn/upload_h.php";
var files=[];

function upload(){
	if(files.length<=0){
		plus.nativeUI.alert("没有添加上传文件！");
		return;
	}
	var wt=plus.nativeUI.showWaiting();
	var task=plus.uploader.createUpload(server,
		{method:"POST"},
		function(t,status){ //上传完成
			if(status==200){
				plus.storage.setItem("uploader",t.responseText);
				data = eval("(" + t.responseText + ")");
					imgaes_url = "http://insure.unair.cn/" + data['files']['uploadkey1']['url'];
					$("#jiajia").hide();
					var src = '<img src="' +imgaes_url+ '" style="width: 200px;height:150px;"/>'
					$("#headimg1").html(src)
				wt.close();
//				alert(JSON.stringify(data['files']['uploadkey1']['url']))
		}else{
				wt.close();
			}
		}
	);
	task.addData("client","HelloH5+");
	task.addData("uid",getUid());
	for(var i=0;i<files.length;i++){
		var f=files[i];
		task.addFile(f.path,{key:f.name});
	}
	task.start();
}
		// 拍照添加文件
function appendByCamera(){
	plus.camera.getCamera().captureImage(function(p){
		appendFile(p);
		upload();
	});	
}
// 从相册添加文件
function appendByGallery(){
	plus.gallery.pick(function(p){
        appendFile(p);
        upload();
    });
}
// 添加文件
var index=1;
function appendFile(p){
	var fe=document.getElementById("files");
	var li=document.createElement("li");
	var n=p.substr(p.lastIndexOf('/')+1);
	li.innerText = n
	fe.appendChild(li);
	files.push({name:"uploadkey"+index,path:p});
	index++;
	empty.style.display="none";
}
// 产生一个随机数
function getUid(){
	return Math.floor(Math.random()*100000000+10000000).toString();
}
		</script>
	</head>
	<body>
		<div class="app_head pre">
            <div class="app_prev do_back"  onclick="clicked('./myinfo.html')"><img src="../img/arrow.png" /></div>
            <div class="app_head_text">油卡充值申请</div>
            <!--<div class="app_prev" style="color:red;" onclick="clicked('./cecharge_history.html')">充值记录</div>-->
        </div>
            <ul id="files" style="text-align:left;display:none;">
				<p id="empty" style="font-size:12px;color:#C6C6C6;">无上传文件</p>
			</ul>
        <div class="app_body" id="car_2">
            <div class="main_in_input" style="height:80px;">
                <div style="float:left;font-size:20px;margin-left:-10px;margin-top:28px;width:120px;text-align:right;">申请账号:</div>
                <div style="float:left;font-size:18px;padding-left:5%;margin-top:18px;width:70%;">
                    <input style="width:100%;height:50px;font-size:20px;border:none;" disabled="true" id="lgname" >
                </div>
            </div>
            <div class="main_in_input" style="height:80px;">
                <div style="float:left;font-size:20px;margin-left:-10px;margin-top:28px;width:120px;text-align:right;">申请人:</div>
                <div style="float:left;font-size:18px;padding-left:5%;margin-top:18px;width:70%;">
                    <input style="width:100%;height:50px;font-size:20px;border:none;" id="name" placeholder="请输入申请人姓名" value="">
                </div>
            </div>
            <div class="main_in_input" style="height:80px;">
                <div style="float:left;font-size:20px;margin-left:-10px;margin-top:28px;width:120px;text-align:right;">油卡类型:</div>
                <div style="float:left;font-size:20px;padding-left:5%;margin-top:14px;width:70%;">
                    <select style="width:100%;height:55px;font-size:20px;" id="cartype">
                        <option value="1">中国石化</option>
                    </select>
                </div>
            </div>
            <div class="main_in_input" style="height:80px;">
                <div style="float:left;font-size:20px;margin-left:-10px;margin-top:28px;width:120px;text-align:right;">油卡卡号:</div>
                <div style="float:left;font-size:18px;padding-left:5%;margin-top:18px;width:70%;">
                    <input style="width:100%;height:50px;font-size:20px;border:none;" id="carid" placeholder="请输入油卡卡号">
                </div>
            </div>
            <div class="main_in_input" style="height:80px;">
                <div style="float:left;font-size:20px;margin-left:-10px;margin-top:28px;width:120px;text-align:right;">充值金额:</div>
                <div style="float:left;font-size:18px;padding-left:5%;margin-top:18px;width:70%;">
                    <input style="width:100%;height:50px;font-size:20px;border:none;" id="money" placeholder="请输入凭证上的充值金额">
                </div>
            </div>
            <div class="main_in_input per1"  style="margin-top:15px;height:220px;">
                <div style="margin-left:22%;font-size:18px;">请上传充值成功凭证</div>
                <div onclick="showActionSheet(this)" id="headimg1" style="height:150px;width:200px;border:1px solid black;margin-left:22%;margin-top:10px;">
                <!--<div onclick="clicked('./upload.html')" id="headimg1" style="height:150px;width:200px;border:1px solid black;margin-left:22%;margin-top:10px;">-->
                    <span id="jiajia" style="font-size:105px;margin-left:60px;">+</span>
                    
                </div>
            </div>
            <div class="main_in_input" style="height:150px;">
                <div style="float:left;font-size:20px;margin-left:-10px;margin-top:28px;width:120px;text-align:right;">充值说明:</div>
                <div style="float:left;font-size:18px;padding-left:2%;margin-top:18px;width:70%;">
<!--                    <input style="width:100%;height:50px;font-size:20px;border:none;" id="idcard" placeholder="说明">-->
                    <textarea style="margin-top:10px;width:100%;height:100px;font-size:20px;" id="remark"></textarea>
                </div>
            </div>
            <div style="background:white;height:120px;">
                <div class="app_submit left"  style="width:40%;margin-left:5%;float: left;" onclick="clicked('./myinfo.html')">取消</div>
                <div class="app_submit left" style="width:40%;margin-left:5%;float: left;" onclick="doadd()">提交申请</div>
            </div>
        </div>
        
        <div class="outside_pull"></div>
        <img src="../img/loading.gif" class="fade_out_img" id="fade_out_loading" />
	</body>
	<script type="text/javascript" src="../js/immersed.js" ></script>
	<script>
		function showActionSheet(conf){
          var divid = conf.id;  
              var actionbuttons=[{title:"拍照"},{title:"相册"}];  
              var actionstyle={title:"选择照片",cancel:"取消",buttons:actionbuttons};  
              plus.nativeUI.actionSheet(actionstyle, function(e){  
                    if(e.index==1){
                        appendByCamera()
                    }else if(e.index==2){  
                        appendByGallery()
                    }  
              } );  
        }

	</script>
</html>
